﻿<Window x:Class="YiJing.Views.CoinTossView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended" 
            WindowStartupLocation="CenterOwner" ResizeMode="NoResize" 
             mc:Ignorable="d" Width="380" Height="300"
             d:DesignHeight="300">
    <DockPanel Margin="4">
        <DockPanel.Resources>
            <Style TargetType="Label">
                <Setter Property="Width" Value="50" />
                <Setter Property="HorizontalContentAlignment" Value="Right" />
            </Style>

            <Style x:Key="Spin" TargetType="Controls:IntegerUpDown">
                <Setter Property="Width" Value="70" />
                <Setter Property="Margin" Value="0,2,0,2" />
            </Style>

            <Style TargetType="Button">
                <Setter Property="MinWidth" Value="85" />
                <Setter Property="Margin" Value="5,0,0,0" />
            </Style>

            <DataTemplate x:Key="LineVisual" DataType="Line" >
                <Grid Margin="0,3,0,3" SnapsToDevicePixels="true">
                    <Grid.Resources>
                        <Style TargetType="Rectangle">
                            <Setter Property="Fill" Value="DarkSlateBlue" />
                            <Setter Property="StrokeThickness" Value="0" />
                        </Style>
                    </Grid.Resources >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="5*" />
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="5*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Rectangle Grid.Column="0" />
                    <Rectangle Grid.Column="2"/>
                    <Rectangle Grid.Column="0" Grid.ColumnSpan="3" Name="Full" />
                    <Ellipse Name="Spot" Grid.Column="4" Margin="4,0,0,0" Width="12" Height="12" Fill="DarkSlateBlue" />
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsBroken}" Value="True">
                        <Setter TargetName="Full" Property="Visibility" Value="Hidden" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsMoving}" Value="False">
                        <Setter TargetName="Spot" Property="Visibility" Value="Hidden" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </DockPanel.Resources>

        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,4,0,0">
            <Button x:Name="OK" Content="OK" />
            <Button Content="Cancel" IsCancel="true" />
        </StackPanel>

        <StackPanel DockPanel.Dock="Right">
            <StackPanel.Resources>
                <Style TargetType="Button">
                    <Setter Property="MinWidth" Value="85" />
                    <Setter Property="Margin" Value="5,0,0,5" />
                </Style>

            </StackPanel.Resources>
            <Button x:Name="Add" Content="_Add" />
            <Button x:Name="Remove" Content="_Remove" />
            <Button x:Name="Clear" Content="Clear" />
            <Label/>
            <Button x:Name="AddRandom" Content="Toss _One" />
            <Button x:Name="AddAll" Content="Co_mplete" />
        </StackPanel>

        <Border BorderThickness="1" BorderBrush="LightGray">
            <DockPanel>
                <StackPanel DockPanel.Dock="Top" Orientation="Vertical" HorizontalAlignment="Stretch">

                    <!-- Coins -->
                    <StackPanel Orientation="Horizontal" DataContext="{Binding CoinToss}" HorizontalAlignment="Center" >
                        <StackPanel.Resources>
                            <Style TargetType="CheckBox">
                                <Setter Property="Margin" Value="4" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="CheckBox">
                                            <Grid Width="48" Height="48">
                                                <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}"  />
                                                <Ellipse StrokeThickness="2" Stroke="Gold" Fill="LemonChiffon" />
                                                <Image Name="tick" Source="../Assets/coin.png" Width="64" Height="64" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsChecked" Value="False">
                                                    <Setter TargetName="tick" Property="Visibility" Value="Hidden" />
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </StackPanel.Resources>
                        <CheckBox IsChecked="{Binding Path=Coins[0].IsHeadUp}" />
                        <CheckBox IsChecked="{Binding Path=Coins[1].IsHeadUp}" />
                        <CheckBox IsChecked="{Binding Path=Coins[2].IsHeadUp}" />
                    </StackPanel>

                    <!-- Edit fields -->
                    <UniformGrid Columns="2" HorizontalAlignment="Center">
                        <UniformGrid.Resources>
                            <Style x:Key="CoinCount" TargetType="Controls:IntegerUpDown" BasedOn="{StaticResource Spin}">
                                <Setter Property="Minimum" Value="0" />
                                <Setter Property="Maximum" Value="3" />
                                <Setter Property="IsEditable" Value="false" />
                            </Style>
                        </UniformGrid.Resources>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Label Content="Heads:" Grid.Row="0" />
                            <Controls:IntegerUpDown Watermark="Enter Heads" Grid.Row="0" Grid.Column="1" Value="{Binding Path=CoinToss.HeadsCount}" Style="{StaticResource CoinCount}" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Label Content="Tails:" Grid.Column="2"/>
                            <Controls:IntegerUpDown Watermark="Enter Tails" Grid.Row="1" Grid.Column="3" Value="{Binding Path=CoinToss.TailsCount}" Style="{StaticResource CoinCount}"/>
                        </StackPanel>
                    </UniformGrid>
                </StackPanel>

                <ItemsControl ItemsSource="{Binding Path=Lines}" Margin="6" Width="120" IsTabStop="false" VerticalAlignment="Bottom" ItemTemplate="{StaticResource LineVisual}" >
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="1" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </DockPanel>
        </Border>
    </DockPanel>
</Window>
